package org.edu.modules.oa.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.edu.modules.oa.entity.*;
import org.edu.modules.oa.mapper.IVeOaMeetAttenMapper;
import org.edu.modules.oa.mapper.IVeOaMeetMapper;
import org.edu.modules.oa.mapper.IVeOaMeetUsersMapper;
import org.edu.modules.oa.service.IVeOaMeetManageService;
import org.edu.modules.oa.vo.VeOaMeetManageTableVo;
import org.edu.modules.oa.vo.VeOaMeetSelectByIdVo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;

@Service
public class VeOaMeetMangeServiceImp implements IVeOaMeetManageService {

    @Resource//会议表
    private IVeOaMeetMapper veOaMeetMapper;

    @Resource
    private IVeOaMeetUsersMapper veOaMeetUsersMapper;

    @Resource
    private IVeOaMeetAttenMapper veOaMeetAttenMapper;
    //加载表格
    public HashMap<String, Object> loadMeet(Integer current, Integer pageSize, VeOaMeetEntity veOaMeetEntity) {
        HashMap<String,Object> map = new HashMap<>();
        String title = "%"+veOaMeetEntity.getTitle()+"%";
        Integer placeId = veOaMeetEntity.getPlaceId();
        List<VeOaMeetManageTableVo> list = veOaMeetMapper.selectMeetManage(current,pageSize,title,placeId);
        int count = veOaMeetMapper.countMeetManage(title,placeId);
        map.put("list",list);
        map.put("count",count);
        return map;
    }

    //查看会议详情
    public VeOaMeetSelectByIdVo selectMeetById(Integer id) {
        VeOaMeetSelectByIdVo veOaMeetUsersEntity = veOaMeetMapper.selectMeetById(id);
        QueryWrapper<VeOaMeetAttenEntity> wrapper = new QueryWrapper<>();
        wrapper.eq("meet_id", id);
        List<VeOaMeetAttenEntity> list = veOaMeetAttenMapper.selectList(wrapper);
        String userName = "";
        for (VeOaMeetAttenEntity v : list) {
            userName += v.getUserName()+",";
        }
        veOaMeetUsersEntity.setUserName(userName);
        return veOaMeetUsersEntity;
    }



}

